export interface RoleItem {
  roleId: number
  roleCode: string
  roleName: string
  subVisible: 0 | 1
  roleOrgCode: number
  roleOrgName: string
  description: string
  inheritedOrgCode: string
  inheritedOrgName: string
  inheritedRoleId: number
  inheritedRoleName: string
  remark: string
  createTime: string
  createBy: number
  createName: string
  updateTime: string
  updateBy: number
}

// 搜索参数
export interface RoleSearchParams {
  scope: any
  orgCode: any
  current: number | undefined
  size: number | undefined
}

// 分页数据
export interface RolePageData {
  current: string
  size: string
  total: string
  records: RoleItem[]
}

export type DefaultRow = Record<PropertyKey, any>;
export interface FetchPrams {
  pageNum?: number
  pageSize?: number
  [key: string]: any
}
export interface AuthNode {
  id?: number
  code: string
  name: string
  type: string
  authorized: number // 0=未授权，1=已授权
  inherited: number // 0=非继承，1=继承
  children?: AuthNode[] // 递归嵌套子节点
}

export interface AppNode extends AuthNode {
  id: number
  appCode: string
  appName: string
  type: string
}

// 授权树整体数据类型（根节点为AppNode数组）
export type AuthTree = AppNode[];

export interface PermissionSaveResult {
  code: number
  message: string
}

export interface SelectedPermissions {
  function: any[]
  data: any[]
  admin: any[]
  column: any[]
}

export interface MiTreeSelectorInstance {
  getCheckedKeys: () => string[]
  getTreeData: () => any[]
  setCheckedKeys: (key: string[]) => void
}
export interface TreeSelectorRefs {
  [key: string]: MiTreeSelectorInstance | undefined
}

// 树节点数据类型
export interface TreeNode {
  id: number
  code: string
  label: string
  orgFullName: string
  type: string
  parentCode: string
  isLeaf: number
  isExtend: number
  canCheck: number
  createBy: string
  updateBy: string
  createTime: string
  updateTime: string
  fullCodePath: string
  bindOrgCode: string
  children: []
}
export interface OrgTreeNode {
  mapKey: TreeNode[]
  root: TreeNode[]
}

export interface TreeRequestParams {
  orgCode: string
  loadType: string
  isTree: 0
  menuId: string
  sessionId: string
  queryTime: string
  keyword: string
  extendCondition: [
    {
      field: string
      operator: string
      value: string
    },
  ]
}

// 获取授权页面数据
export interface TransferParams {
  roleId: string
  orgCode: string
}

export interface TreeNodeCharacter {
  id: number
  code: string
  name?: string
  type: string
  authorized?: number
  inherited?: number
  appId?: string
  children?: TreeNodeCharacter[]
}

// 所有的tab页
export interface PermissionTab {
  name: string
  label: string
}
export interface AppNodeCharacter {
  id: number // 添加 id 属性
  appCode: string
  appName: string
  children: TreeNodeCharacter[]
}

export interface AppIdsMap {
  [appId: string]: number[] // 修改为 appId 作为键
}
export interface ChildComponentMethods {
  clearText: () => void
}

export interface RoleData {
  roleCode: string
  roleName: string
  responsibilityScope: string
  description: string
  orgLevel: string
  inheritedOrgName: string
  inheritedRoleName: string
}
export interface AuthTreeCharacter {
  data: any[]
}

export type TreeSelectorCharacterRefs = Record<string, MiTreeSelectorInstance>;
export interface FunctionItem {
  id: number
  code: string
  type: number
  appId: string
}
export interface RoleSaveRequest {
  roleId: string
  orgCode: string
  deletedFunctions: TreeNodeCharacter[]
  addFunctions: TreeNodeCharacter[]
}
export interface PermissionItem {
  id: string | number
  code: string
  name: string
  type: string
  authorized?: number
  children?: PermissionItem[]
}

export interface TransformedPermissionItem {
  id: string | number
  code: string
  label: string
  type: string
  authorized?: number
  children?: TransformedPermissionItem[]
}

export interface TreeTransFormed {
  orgCode: string
  isTree: string
  loadType: string
  extendcondition: string
}

// 添加缺失的类型定义
export interface GroupedFunctionalResult {
  authorized0: TreeNodeCharacter[]
  authorized1: TreeNodeCharacter[]
}
